package service;

import annotation.PrivilegeAnno;
import dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pojo.User;

import java.util.List;

@Service("target")
public class UserServiceImpl implements UserService {
                //userServiceImpl

    @Autowired
    private UserDao userDao;
    /*@Autowired
    private TransactionManager tx;*/

    /*
    * @Autowired
    * private TransactionManager tx;
    *
    * */

    @Override
    //@Transaction
    @PrivilegeAnno(name="add")
    public void addUser(User user) {

        //tx.open1();
        //处理数据的业务逻辑
        //int i=10/0;
        userDao.add(user);

        //tx.commit();

        /**
         * 1、根据需求，编写事物控制的模块  tx.TransactionManager
         * 2、根据需求，使用静态代理模式，编写代理类 proxy.Proxy
         * 3、根据流程图，完成各层之间的关系。
         *
         */
    }

    @Override
    @PrivilegeAnno(name="update")
    public void updateUser(User user) {

        userDao.update(user);

    }

    @Override
    @PrivilegeAnno(name="delete")
    public void delete(int id) {
        userDao.delete(id);
    }

    @Override
    @PrivilegeAnno(name="findUserAll")
    public List<User> findUserAll() {
        return  userDao.findUserAll();
    }

    @Override
//    @PrivilegeAnno(name="findUserById")
    public User findUserById(int id) {
        return userDao.findUserById(id);
    }

}
